<template>
    <a-card :bordered="false">
        <!-- <div class="table-operator">
            <a-button shape="round" size="small" type="primary" icon="plus" @click="handleEdit({},'templateDetailForm','新增')">添加</a-button>
        </div> -->
        <a-tag style="margin-bottom: 8px;font-size:14px;" color="#87d068">字段标题、名称、排序不能重复</a-tag>
        <LTable
            ref="templateDetailList"
            size="middle"
            rowKey="keyId"
            :formAttributes="formAttributes"
            :columns="columns"
            axiosUrl="/SysImportTemplateDetailController/list"
            :initQuery="initQuery"
            :initOrder="initOrder"
            :showPagination="false"
            :showQueryForm="true">
    
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record,'templateDetailForm','模板详情')">编辑</a>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete({keyId:record.keyId},'/SysImportTemplateDetailController/del','templateDetailList')">
                  <a>删除</a>
            </a-popconfirm>
        </span>
        
    </LTable>

    
    <templateDetailForm :templateDetailList="this" ref="templateDetailForm" @close="refresh('templateDetailList')" @ok="refresh('templateDetailList')"></templateDetailForm> 
    </a-card>
</template>

<script>
import LTable from '@/components/lt/LTable'
import templateDetailForm from './templateDetailForm'
import {SysMixin} from '@/mixins/SysMixin'
import defaultSettings from '@/config/defaultSettings'



export default {
    name:'templateList',
    components:{
       LTable,templateDetailForm
    },
    props:{
        componentParam:{
            type:Object,
            default:()=>{}
        },
    },
    mixins:[SysMixin],
    data(){
        return{
            initDictCodes:defaultSettings.数据字典.是否,
            defaultSettings,
            formAttributes:[],
            initQuery:[{field:'templateId',val:'-112'}],
            initOrder:[{field:'fieldOrder',val:'asc'}],
            columns:[
                {
                    title: '序号',
                    dataIndex: '',
                    key:'rowIndex',
                    width:60,
                    align:"center",
                    customRender:function (t,r,index) {
                      return parseInt(index)+1;
                    }
                },
                
               {
                    title: '数据库字段名称',
                    dataIndex: 'dbField'
                    
                },
                {
                    title: '实体字段名称',
                    dataIndex: 'fieldName'
                    
                },
                {
                    title: '字段标题',
                    dataIndex: 'fieldTitle'
                },
                {
                    title: '下拉数据源',
                    dataIndex: 'dictCode'
                    
                },
                {
                    title: '字段排序',
                    dataIndex: 'fieldOrder'
                },
                {
                    title: '是否模板字段',
                    dataIndex: 'isImport',
                    customRender:(text)=>{
                        if(!text){
                            return ''
                        }else{
                            return this.dictText(defaultSettings.数据字典.是否,text)
                        }
                    }
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    width: '120px',
                    scopedSlots: { customRender: 'action' }
                }
            ],
            
        }
    },
    created(){
        this.queryByTemplateId()
    },
    watch: {
     componentParam: {
         handler: function() {
            this.queryByTemplateId()
         },
         deep: true
     }
    },
    methods:{
        queryByTemplateId(){
            if(this.componentParam && this.componentParam['templateId']){
                this.initQuery=[{field:'templateId',val:this.componentParam['templateId']}]
                this.$nextTick(() => {
                    this.$refs['templateDetailList'].searchQuery()
                })
                
                
            }
        }
       
    }
}
</script>